﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LogManager.Base;
using LogManager.Base.Data;
using LogManager.LocalStorage.Data;

namespace LogManager.Windows.Data
{
    public class CachedWindowsEventService : IEventService
    {
        private CachedEventRepository _cache;
        private WindowsEventService _remote;

        public CachedWindowsEventService(WindowsLog log)
        {
            _remote = new WindowsEventService(log);
            _cache = new CachedEventRepository(log);
        }

        public IQueryable<IEvent> WithType(string typeId)
        {
            _cache.Sync(_remote);
            return _cache.WithType(typeId);
        }

        public IEvent Get(string id)
        {
            _cache.Sync(_remote);
            return _cache.Get(id);
        }

        public IQueryable<IEvent> Query()
        {
            _cache.Sync(_remote);
            return _cache.Query();
        }

        public IQueryable<IEvent> Between(DateTime start, DateTime end)
        {
            _cache.Sync(_remote);
            return _cache.Between(start, end);
        }

        public IEnumerable<IEvent> All()
        {
            _cache.Sync(_remote);
            return _cache.All();
        }

        public void Dispose()
        {
            _cache.Dispose();
            _remote.Dispose();
        }
    }
}
